package com.hxy.platform.admin.service.impl;

import com.hxy.platform.admin.dao.UserMapper;
import com.hxy.platform.admin.pojo.User;
import com.hxy.platform.admin.service.UserService;
import com.hxy.platform.admin.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    /**
     * 获取所有普通用户
     * @return
     */
    @Override
    public List<User> getAll() {
        return userMapper.getAll();
    }

    /**
     * 删除会员
     * @param id
     * @return
     */
    @Override
    public int deleteById(Integer id) {
        return userMapper.deleteByPrimaryKey(id);
    }

    /**
     * 查询所有管理员信息
     * @return
     */
    @Override
    public List<User> getAdminUser() {
        return userMapper.getAdminUser();
    }

    /**
     * 添加管理员用户
     * @param email
     * @param password
     * @return
     */
    @Override
    public int addAdminUser(String email, String password) {
        User newUser = new User();
        newUser.setPassword(MD5Util.MD5EncodeUtf8(password));
        newUser.setEmail(email);
        newUser.setStatus(1);
        newUser.setType(1);
        return userMapper.insertSelective(newUser);
    }
}
